package com.rdc.qingkou.ui;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.rdc.qingkou.Application.MyApplication;
import com.rdc.qingkou.R;
import com.rdc.qingkou.utils.LabelSharedPreferencesUtils;

/**
 * Created by asus on 2017/8/6.
 */

public class CustomLabelDialogActivity extends AppCompatActivity implements View.OnClickListener {
    private EditText mCustomLabel;
    private TextView mCancel;
    private TextView mConfirm;
    private TextView mLabelOne;
    private TextView mLabelTwo;
    private TextView mLabelThree;
    private Intent intent = new Intent();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        MyApplication.addActivity(this);
        setContentView(R.layout.send_customlabel);

        init();
    }


    private void init(){
        mCustomLabel = (EditText)findViewById(R.id.et_InputLabel);
        mCancel = (TextView)findViewById(R.id.tv_cancel);
        mConfirm = (TextView)findViewById(R.id.tv_confirm);
        mLabelOne = (TextView) findViewById(R.id.tv_label_one);
        mLabelTwo = (TextView) findViewById(R.id.tv_label_two);
        mLabelThree = (TextView) findViewById(R.id.tv_label_three);

        LabelSharedPreferencesUtils spUtil = new   LabelSharedPreferencesUtils(this);
        mLabelOne.setText(spUtil.getString("LabelOne"));
        mLabelTwo.setText(spUtil.getString("LabelTwo"));
        mLabelThree.setText(spUtil.getString("LabelThree"));
        mLabelOne.setOnClickListener(this);
        mLabelTwo.setOnClickListener(this);
        mLabelThree.setOnClickListener(this);
        mCancel.setOnClickListener(this);
        mConfirm.setOnClickListener(this);
        mCustomLabel.setText("");

    }

    @Override
    public void onClick(View v) {

        switch (v.getId()){
            case R.id.tv_cancel:
                intent.putExtra("CustomLabel","");
                setResult(RESULT_OK,intent);
                finish();
                break;
            case R.id.tv_confirm:
                intent.putExtra("CustomLabel",""+mCustomLabel.getText().toString());
                setResult(RESULT_OK,intent);
                finish();
                break;
            case R.id.tv_label_one:
                mCustomLabel.setText(mLabelOne.getText());
                mCustomLabel.setSelection(mLabelOne.getText().length());
                break;
            case R.id.tv_label_two:
                mCustomLabel.setText(mLabelTwo.getText());
                mCustomLabel.setSelection(mLabelTwo.getText().length());

                break;
            case R.id.tv_label_three:
                mCustomLabel.setText(mLabelThree.getText());
                mCustomLabel.setSelection(mLabelThree.getText().length());

                break;
            default:
                break;



        }

    }

    @Override
    public void onBackPressed() {

        intent.putExtra("CustomLabel","");
        setResult(RESULT_OK,intent);
        finish();
    }
}
